package com.hue.springbootmybatisplus.controller;

import com.hue.springbootmybatisplus.domain.User;
import com.hue.springbootmybatisplus.service.UserService;
import com.hue.springbootmybatisplus.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getAll")
    public Object getAll() {
        return new R(200, "获取成功", userService.list());
    }

    @PostMapping("/getAll1")
    public Object getAll1(@RequestBody Map<String, Object> param) {
        System.out.println(param);
        return new R(200, "获取成功", userService.list());
    }

    @GetMapping("/save/{name}/{age}")
    public Object getAll(@PathVariable("name") String name, @PathVariable("age") Integer age) {
        userService.save(new User(name, age));
        return "添加成功";
    }

    @GetMapping("delete/{id}")
    public String delete(@PathVariable("id") String id) {
        boolean b = userService.removeById(id);
        return "删除成功";
    }
}
